//
//  MCBillingInfoHeadView.swift
//  StoreManage
//
//  Created by MC on 2018/8/10.
//  Copyright © 2018年 MC. All rights reserved.
//

import UIKit

typealias MCBillingInfoHeadView_categoryClosure   = () -> Void
typealias MCBillingInfoHeadView_chooseTimeClosure = () -> Void

class MCBillingInfoHeadView: UIView {

    
    var categoryClosure : MCBillingInfoHeadView_categoryClosure?
    var timeClosure : MCBillingInfoHeadView_chooseTimeClosure?

    var dataDict = Dictionary<String,Any>() {
        didSet {
            let orderCount = dataDict["orderCount"] as? NSNumber ?? 0
            let totalFee = dataDict["totalFee"] as? NSNumber ?? 0
            
            let moneyStr = MCString_judgemantDecimalsIsZero(figure: totalFee.intValue)
            
            moneyLabel.attributedText = moneyStr.MCAttributedString_font(font: 35, range: NSRange.init(location: 1, length: moneyStr.count - 1))
            countLabel.text = "共计" + orderCount.stringValue + "笔"
        }
    }
    
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.backgroundColor = UIColor.MCGray_light
        self.frame = CGRect.init(x: 0, y: 0, width: MCScreenWidth, height: 176)
        
        
        self.addSubview(bgView)
        bgView.snp.remakeConstraints { (make) ->Void in
            make.edges.equalTo(self).inset(UIEdgeInsetsMake(0, 0, 56, 0))
        }
        
        
        bgView.addSubview(moneyLabel)
        moneyLabel.snp.remakeConstraints { (make) ->Void in
            make.centerX.equalTo(bgView)
            make.top.equalTo(bgView.snp.centerY).offset(-2)
        }
        
        bgView.addSubview(chooseButton)
        chooseButton.snp.remakeConstraints { (make) ->Void in
            make.centerX.equalTo(bgView)
            make.top.equalTo(20)
            make.size.equalTo(CGSize.init(width: 110, height: 30))
        }
        
        
        bgView.addSubview(categoryLabel)
        categoryLabel.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(15)
            make.top.equalTo(bgView.snp.bottom).offset(10)
        }
        
        bgView.addSubview(countLabel)
        countLabel.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(15)
            make.top.equalTo(categoryLabel.snp.bottom).offset(5)
        }
        
        
        self.addSubview(calendarButton)
        calendarButton.snp.remakeConstraints { (make) ->Void in
            make.right.equalTo(-15)
            make.size.equalTo(CGSize.init(width: 34, height: 34))
            make.top.equalTo(bgView.snp.bottom).offset(11)
        }
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    @objc func chooseButtonClicked() {
        categoryClosure?()
    }
    
    @objc func chooseTimeButtonClicked() {
        timeClosure?()
    }
    
    
    lazy var bgView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.MCMain
        return view
    }()
    
    lazy var moneyLabel: UILabel = {
        let label = UILabel()
        label.font = MCFont(16)
        label.text = "¥0"
        label.textColor = UIColor.white
        return label
    }()
    
    
    lazy var chooseButton: MCReverseHorizontalButton = {
        let button = MCReverseHorizontalButton()
        button.backgroundColor = UIColor.clear
        button.iconImageView.image = #imageLiteral(resourceName: "Reuse_triangle_black_bottom").MCImageWithTintColor(color: UIColor.white)
        button.nameLabel.text = "全部收入"
        button.nameLabel.textColor = UIColor.white
        button.nameLabel.font = MCFont(14)
        button.addTarget(self, action: #selector(chooseButtonClicked), for: UIControlEvents.touchUpInside)
        return button
    }()
    
    
    lazy var categoryLabel: UILabel = {
        let label = UILabel()
        label.font = MCFont(14)
        label.text = "全部"
        label.textColor = UIColor.MCWords
        return label
    }()
    
    lazy var countLabel: UILabel = {
        let label = UILabel()
        label.font = MCFont(13)
        label.text = "共计23876笔"
        label.textColor = UIColor.MCGray_middle
        return label
    }()
    
    lazy var calendarButton: UIButton = {
        let button = UIButton.init(type: UIButtonType.custom)
        button.setImage(#imageLiteral(resourceName: "Ticket_calendar").MCImageWithTintColor(color: UIColor.MCGray_middle), for: .normal)
        button.addTarget(self, action: #selector(chooseTimeButtonClicked), for: UIControlEvents.touchUpInside)

        return button
    }()
}
